package com.example.mapper;

import com.example.pojo.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserMapper {
    //获取所有用户
    @Select("SELECT * FROM users")
    List<User> getUsers();

    //新增用户
    @Insert("INSERT INTO users (username, password) VALUES (#{username}, #{password})")
    int insertUser(User user);
    //更新用户
    @Update("UPDATE users SET name = #{name}, age = #{age}, sex = #{sex}, birthday = #{birthday}, introduction = #{introduction}, phone = #{phone},avatar_url = #{avatarUrl}, email = #{email}  WHERE id = #{id}")
    void updateUser(User user);
    //根据id查询用户
    @Select("SELECT * FROM users WHERE id = #{id}")
    User findUserById(Integer id);

    //根据用户名查询用户
    @Select("SELECT * FROM users WHERE username = #{username}")
    User findUserByUsername(String username);

    //删除用户
    @Update("DELETE FROM users WHERE id = #{id}")
    void deleteUserById(Integer id);
}
